﻿using System;
using System.Collections;

namespace SDFL.KeyPoints.DesignPattern.Strategy.RealWorld
{
    // "Context" 
    class SortedList
    {
        private ArrayList list = new ArrayList();

        // maintains a reference to a Strategy object
        private SortStrategy sortstrategy;

        // configured with a ConcreteStrategy object
        public void SetSortStrategy(SortStrategy sortstrategy)
        {
            this.sortstrategy = sortstrategy;
        }

        public void Add(string name)
        {
            list.Add(name);
        }

        // define an interface that lets Strategy access its method.
        public void Sort()
        {
            sortstrategy.Sort(list);

            // Display results 
            foreach (string name in list)
            {
                Console.WriteLine(" " + name);
            }
            Console.WriteLine();
        }
    }
}
